Skip to content

Add Make-native test target across all examples - #445

Merged
sshi-amd merged 6 commits into
ROCm:amd-stagingfrom
sshi-amd:makefiles-testing-pr2
Apr 24, 2026
Merged

sshi-amd merged 6 commits into
ROCm:amd-stagingfrom
sshi-amd:makefiles-testing-pr2

Conversation

@sshi-amd

@sshi-amd sshi-amd commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Closes the testing half of the Make-build CI work that was deferred from #442. With this PR make test from the repo root builds and runs every leaf example that registered an add_test in CMake, matching the existing CMake/CTest coverage. CI just orchestrates; all test command/args/timeout logic lives in the Makefiles.

This PR is stacked on top of #442 — its diff against amd-staging will look much smaller once #442 lands.

Technical Details

Leaf Makefile test: target

Every leaf Makefile gains a test: target depending on its build target. Default invocation:

.PHONY: test
test: $(EXAMPLE)
	./$(EXAMPLE) $(TEST_ARGS)
  • TEST_ARGS is empty by default. HIP-Doc/Tutorials/Programming-Patterns/bfs/Makefile sets TEST_ARGS := graph4096.txt to mirror its CMake add_test.
  • Leaves whose CMakeLists has no add_test() get an empty no-op test: (e.g. HIP-Basic/{opengl_interop, vulkan_interop, static_device_library}, Libraries/MIVisionX/{canny, mv_objdetect, opencv_orb}, three rocDecode examples that don't register).
  • REQUIRED_DEPS leaves (~28) extend their existing SKIP_BUILD else no-op block with test: alongside all:/clean:.

Parent Makefile cascade with per-parent skip list

Every parent Makefile (root + ~80 intermediates) declares SKIP_FROM_TEST := and:

test: TARGET=test
test: $(filter-out $(SKIP_FROM_TEST),$(EXAMPLES))

So make test cascades through the tree, skipping any subdirs the parent has explicitly excluded.

Libraries/rocDecode/Makefile populates SKIP_FROM_TEST := $(EXAMPLES): all rocDecode examples need test data (videos under $(ROCM_PATH)/share/rocdecode/) that ctest currently guards behind if(EXISTS …) checks. Encoding that conditional logic in Make is doable but noisy; deferring to a follow-up. The leaf rocDecode Makefiles still have working test: targets so they can be run standalone via cd Libraries/rocDecode/<example> && make test.

Common/find_filesystem.mk cleanup

The PR also converts the 19 remaining leaves with hard-coded -lstdc++fs to use the same Common/find_filesystem.mk probe introduced in #442 for the rocDecode leaves. After this, no leaf Makefile in the tree has a literal -lstdc++fs. Hygiene, not a bug fix — they currently work on all three CI distros.

CI workflow

Adds Makefile test step after the existing test steps and Upload Makefile test logs artifact upload. Both gated with if: !cancelled() to mirror the rest of the test-side steps.

Out of scope (potential follow-ups)

  • Per-GPU-arch test skipping — generate_skip_tests.py is still used by the existing ctest step; PR2's per-directory SKIP_FROM_TEST is coarser.
  • Reduction tutorial gtest binaries (Tutorials/reduction/test/*.hip) — no Makefile builds them today.
  • Wiring up rocDecode's conditional test-data probing (CMake's if(EXISTS ${ROCDECODE_TEST_VIDEO_HEVC}) pattern) — currently the entire rocDecode subtree is skipped at parent level.

Test Plan

  • Smoke-tested locally: bitonic_sort (bare run), bfs (with TEST_ARGS), root cascade dry-run reaches every leaf, Libraries/rocDecode cascade correctly does nothing.
  • CI run after push: pending.

Added/Updated documentation?

  • Yes
  • No, does not apply to this PR.

Included Visual Studio files?

  • Yes
  • No, does not apply to this PR.

Submission Checklist

  • New examples contain proper CMake and Make files. (no new examples)
  • I have updated relevant CI workflows and the new examples are being built and tested in CI.
  • Check and guard against unsupported ASICs if relevant dependent libraries have limited support. (handled via per-parent SKIP_FROM_TEST)
  • Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.

sshi-amd and others added 3 commits April 24, 2026 12:14
Closes the testing half of the Make-build CI work that was deferred from
PR1 (ROCm#442). With this commit `make test` from the repo root builds and
runs every leaf example that registered an add_test in CMake, matching
the existing CMake/CTest coverage. CI just orchestrates; all test
command/args/timeout logic lives in the Makefiles.

Per mentor (@zichguan-amd) design:

- Each leaf Makefile gains a `test:` target depending on its build target.
  Default invocation: `./$(EXAMPLE) $(TEST_ARGS)`. Most leaves set no args.
- bfs sets `TEST_ARGS := graph4096.txt` (mirrors its CMake add_test).
- Leaves whose CMakeLists has no add_test() get an empty no-op `test:`
  (HIP-Basic/{opengl_interop,vulkan_interop,static_device_library} and
  Libraries/MIVisionX/{canny,mv_objdetect,opencv_orb} and three rocDecode
  examples that don't register).
- REQUIRED_DEPS leaves (~28) extend their existing SKIP_BUILD `else`
  no-op block with `test:` alongside `all:`/`clean:`.

Cascade: each parent Makefile (root + ~80 intermediates) declares
`SKIP_FROM_TEST :=` and:

    test: TARGET=test
    test: $(filter-out $(SKIP_FROM_TEST),$(EXAMPLES))

So `make test` cascades through the tree, skipping any subdirs the
parent has explicitly excluded.

`Libraries/rocDecode/Makefile` populates `SKIP_FROM_TEST := $(EXAMPLES)`:
all rocDecode examples need test data (videos under
`$(ROCM_PATH)/share/rocdecode/`) that ctest currently guards behind
`if(EXISTS …)` checks. Encoding that conditional logic in Make is doable
but noisy; deferring to a follow-up. The leaf rocDecode Makefiles still
have working `test:` targets so they can be run standalone via
`cd Libraries/rocDecode/<example> && make test`.

Out of scope (per plan, can land later):

- Per-GPU-arch test skipping (`generate_skip_tests.py` is still used by
  the existing ctest step; PR2's per-directory `SKIP_FROM_TEST` is
  coarser).
- Reduction tutorial gtest binaries (`Tutorials/reduction/test/*.hip`)
  — no Makefile builds them today.

Workflow: adds `Makefile test` step after the existing test steps and
`Upload Makefile test logs` artifact upload. Both gated with
`if: !cancelled()` to mirror the rest of the test-side steps.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
Same conversion as the rocDecode leaves: replace literal `-lstdc++fs`
with `$(CXX_FS_LIB)` and include `Common/find_filesystem.mk`. Keeps
all leaves consistent and surfaces what's actually needed via probe
rather than blanket-adding the flag everywhere.

Affected:
- Applications/fdtd
- HIP-Basic/module_api
- HIP-Doc/.../linker_apis_file
- Libraries/rocJPEG/{rocjpeg_decode, rocjpeg_decode_batched, rocjpeg_decode_perf}
- Libraries/rocProfiler-SDK/{api_buffered_tracing, code_object_isa_decode,
  code_object_tracing, external_correlation_id_request, intercept_table,
  openmp_target, pc_sampling, thread_trace,
  counter_collection/{buffer, buffer_device_serialization, device_profiling,
                      device_profiling_sync, print_functional_counters}}

These currently work on all three CI distros (libstdc++fs is available
as either a stub or the real lib), so this is hygiene rather than a
bug fix. Aligns with the rocDecode probe conversion in the parent
Make-test-target commit.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
1. linker_apis_file/Makefile was missing COMMON_INCLUDE_DIR. The
   prior hygiene cleanup (commit converting hard-coded -lstdc++fs to
   the Common/find_filesystem.mk probe) added an `include
   $(COMMON_INCLUDE_DIR)/find_filesystem.mk` line, but this leaf
   never defined COMMON_INCLUDE_DIR (its example doesn't reference
   any common headers). The include silently failed, make exited 2,
   parent cascade reported `Error 2`. Add the missing definition.

2. Workflow "Makefile test" step now passes
   HIP_ARCHITECTURES="${{ matrix.gpu_config.gpu_target }}" so leaf
   Makefiles using it (e.g. assembly_to_executable's multi-arch
   build) target only the matrix's arch instead of falling back
   to their full hardcoded default list. Without this, the
   `--cuda-device-only -S --offload-arch=<X>` recipe collided
   with CI's HIPCC_COMPILE_FLAGS_APPEND=--offload-arch=gfx1100
   env, producing two `--offload-arch` flags and:
     clang++: error: cannot specify -o when generating multiple
              output files

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@sshi-amd
sshi-amd force-pushed the makefiles-testing-pr2 branch from e113c8c to 0c23b54 Compare April 24, 2026 16:16
The PR2 parent-Makefile updater script regex didn't account for
trailing whitespace on the last line of the EXAMPLES continuation
in the original (`  graph_creation   \n`), so the regex stopped
matching after `graph_capture \` and inserted SKIP_FROM_TEST in
the middle of the multi-line assignment. Result:

  EXAMPLES := \
    graph_capture \

  SKIP_FROM_TEST :=
    graph_creation       ← orphaned, "missing separator" at line 27

Restore the continuation so EXAMPLES contains both children.
HIP-Graphs is the only Makefile that hit this — verified with
`make -n` from each parent: 0 syntax errors tree-wide.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>

@zichguan-amd zichguan-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. TEST_ARGS might need to be aligned with ctest, we can iterate on it later.

@sshi-amd
sshi-amd marked this pull request as ready for review April 24, 2026 18:57
@sshi-amd
sshi-amd requested a review from a team as a code owner April 24, 2026 18:57
For the 7 rocDecode leaves whose CMake `add_test` actually passes
positional args, replace the bare `./$(EXAMPLE) $(TEST_ARGS)` template
with custom recipes that mirror ctest exactly:

- Single-variant leaves (rocdec_decode, video_decode_mem,
  video_decode_perf, video_decode_batch): probe `[ -e <test data> ]`
  and skip cleanly with a "Skipping (not found)" message if the
  ctest data path doesn't exist, mirroring CMake's `if(EXISTS …)`
  register-time guard. Otherwise run the binary with the same
  `-i <path>` (and `-t 2` for batch) ctest passes.
- Multi-variant leaves: ctest registers one test per codec.
  - video_decode      → HEVC, AVC, AV1, VP9 mp4
  - video_decode_raw  → HEVC, AVC, AV1, VP9 raw bitstreams
  - video_decode_rgb  → default + `-resize 640x360`
  Recipe loops through every variant ctest registers, runs each one
  whose input file exists, skips the rest, and returns the worst
  exit code (so a failing AVC doesn't mask a failing AV1 the way
  fail-fast `&&` would).

Per @zichguan-amd review feedback that "TEST_ARGS might need to be
aligned with ctest". TEST_ARGS as a single-string knob doesn't map
cleanly to multi-variant ctest tests; a custom recipe with `$(ROCM_PATH)`
deferred-expanded at use time is the closer parity.

These 7 leaves are still parent-skipped via Libraries/rocDecode/
Makefile's `SKIP_FROM_TEST := $(EXAMPLES)` so the root `make test`
cascade doesn't try them in CI. They become useful when run
standalone (`cd Libraries/rocDecode/<example> && make test`) on a
machine with the rocDecode test data installed under
`$(ROCM_PATH)/share/rocdecode/`.

README also gains a short paragraph documenting the env / CLI
override pattern (`TEST_ARGS=foo make test`).

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@sshi-amd
sshi-amd requested a review from a team as a code owner April 24, 2026 19:07
markdownlint-cli2 MD014/commands-show-output was firing on the
two TEST_ARGS override examples introduced in the prior commit:

  $ make test TEST_ARGS="--size=8192 --verbose"
  $ TEST_ARGS="-i /path/to/video.mp4" make test

The `$` prompt prefix is meant for examples that show command
output; for bare invocations it's just noise that markdownlint
flags. Drop it.

The earlier `$` prefixes (lines 56-58, the git/cd/configure
chain) are inside bullet list items and aren't flagged.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@sshi-amd
sshi-amd merged commit 2af491b into ROCm:amd-staging Apr 24, 2026
32 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants